<?php
namespace Home\Controller;
use Think\Controller;

class IndexController extends Controller{
	public function index(){
		$uname=$_SESSION["uname"];
		if($uname!=""){
			$where["uname"]=$uname;
			$where["status"]=0;
			$res = M('showcar')->where($where)->select();
			$shu =count($res);
			$this->assign("shu",$shu);
		}	
		$urllink = M("urllink");
		$arr = $urllink->select();
		$this->assign("lin",$arr);
		$Ann = M("Ann");
		$ar = $Ann->select();
		$this->assign("arr",$ar);	
		
		$this->display();
	}
	
	public function phoneList(){
		$uname=$_SESSION["uname"];
		if($uname!=""){
			$where["uname"]=$uname;
			$where["status"]=0;
			$res = M('showcar')->where($where)->select();
			$shu =count($res);
			$this->assign("shu",$shu);
		}		
		$res = M("goods")->select();
		$this->assign("res",$res);
		$this->display();		
	}

	public function detail(){
		if($uname!=""){
			$where["uname"]=$uname;
			$where["status"]=0;
			$res = M('showcar')->where($where)->select();
			$shu =count($res);
			$this->assign("shu",$shu);
		}		
		$id = I('get.id');
		$res = M("goods")->find($id);
		$re = M("comment")->where("pid='{$id}'")->select();
		$this->assign("res",$res);
		$this->assign("re",$re);
		$this->display();		
	}

	public function proquery(){
		$pid = I("get.pid");
		$num = I("get.num");
		$res = M("goods")->where("id='{$pid}'")->find();
		$arr["uname"] = $_SESSION["uname"];
		$arr["goods_name"] = $res["goods_name"];
		$arr["pro_img"] = $res["goods_pic"];
		$arr["goods_desc"] = $res["goods_desc"];
		$arr["goods_price"] = $res["goods_price"];
		$arr["pid"] = $res["id"];
		$arr["goods_num"] = $num;
		$arr["goods_pnum"] = $res["goods_num"];
		$r = array();
		$rrr = M('showcar');
		$rv = $rrr->data($arr)->add();
		//print_r($rrr);
		if($rv){
			$uname = $_SESSION["uname"];
			$re = M('showcar')->where(array("status"=>"0","uname"=>"{$uname}"))->select();
			$m = count($re);
			foreach($re as $v){
				$price =$v["goods_num"]*$v["goods_price"];
				$total +=$price;
			}
			$r['status']=true;
			$r['m'] = $m;
			$r['total'] = $total;
		}else{
			$r['status']=false;
		}
		$this->ajaxReturn($r);
	 }



	
}